package com.heyu.cgsd.ui.activity

import android.app.Activity
import android.content.Intent
import android.webkit.WebSettings
import com.heyu.cgsd.R
import com.heyu.cgsd.base.BaseActivity
import kotlinx.android.synthetic.main.activity_user_service_agreement.*
import kotlinx.android.synthetic.main.title_bar_base.*

/**
 * Author:ZJC
 * Date:2020/2/7  16:01
 * Description:UserServiceAgreementActivity
 */
class UserServiceAgreementActivity : BaseActivity() {

    val getAssetsPrivacy = "http://8.129.214.115:8803/"
    val getAssetsUser = "http://8.129.214.115:8802/"

    override fun getContentView(): Int? {
        setTitleBackground(BG_BLACK)
        return R.layout.activity_user_service_agreement
    }

    override fun initView() {
        img_back.setOnClickListener { finish() }
        val type = intent.getIntExtra(TYPE, 0)
        val settings = webview!!.settings
        // 设置缩放
        settings.builtInZoomControls = false
        // 使页面适应用户屏幕
        settings.useWideViewPort = true
        settings.loadWithOverviewMode = true
        settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
        // 开启JavaScript
        settings.javaScriptEnabled = true
        webview!!.isVerticalScrollBarEnabled = false //隐藏垂直滚动条
        if (type == 0) { //用户协议
            tv_title!!.text = "用户协议"
            webview!!.loadUrl(getAssetsUser)
        } else if (type == 1) { //隐私协议
            tv_title!!.text = "隐私政策"
            webview!!.loadUrl(getAssetsPrivacy)
        }
    }

    override fun initData() {}

    companion object {
        const val TYPE = "type"
        @JvmStatic
        fun startAct(activity: Activity, type: Int) {
            val intent = Intent(activity, UserServiceAgreementActivity::class.java)
            intent.putExtra(TYPE, type)
            activity.startActivity(intent)
        }
    }
}